#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2021/12/24 13:34
    Desc  :
--------------------------------------
"""
import httpx
from httpx import Response

from common.utils.log_utils import logger


class CommonRequestClient:
    """"""

    def __init__(self):
        self.url: str = ''
        self.headers: dict = {
            'Content-Type': 'application/json;charset=utf-8'
        }

    def result(self):
        return None


class PostRequestClient(CommonRequestClient):
    """封装的POST请求"""

    def __init__(self):
        super().__init__()
        self.body = None

    def result(self) -> Response:
        logger.info(f'请求:{self.__dict__}')
        res = httpx.post(url = self.url, json = self.body, headers = self.headers, timeout = 100000)
        logger.info(f'响应:{res.text}')
        logger.info(f'耗时:{res.elapsed}')
        return res


class GetRequestClient(CommonRequestClient):
    """封装GET请求"""

    def __init__(self):
        super().__init__()
        self.params = None

    def result(self) -> Response:
        logger.info(f'请求:{self.__dict__}')
        res = httpx.get(url = self.url, params = self.params, headers = self.headers, timeout = 100000)
        logger.info(f'响应:{res.text}')
        logger.info(f'耗时:{res.elapsed}')
        return res


